﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using G.Navigate;

namespace ReadNovel.View.Book
{
    public partial class BookDetailPage : GBasePage
    {
        public BookDetailPage()
        {
            InitializeComponent();
        }
        string articleid = "203086";
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            this.RegisterLoading(null);
            GloabalData.Instance.Client.Execute(new API.Request.Book.BookDetailRequest() { ArticleId = articleid }, (c) =>
            {
                this.UnregisterLoading();
                if (c.IsOk)
                {
                    this.DataContext = c;
                }
                else
                {
                    this.ShowState(c.ErrorMessage);
                }
            });
        }

        private void pivot_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            switch (pivot.SelectedIndex)
            {
                case 0:
                    break;
                case 1:
                    if (listDirectory.ItemsSource == null)
                    {
                        this.RegisterLoading(null);
                        GloabalData.Instance.Client.Execute(new API.Request.Book.BookDirectoryRequest() { ArticleId = articleid }, (c) =>
                        {
                            this.UnregisterLoading();
                            if (c.IsOk)
                            {
                                listDirectory.ItemsSource = c.Chapter_info;
                            }
                            else
                            {
                                this.ShowState(c.ErrorMessage);
                            }

                        });
                    }
                    break;
                case 2:
                    break;
            }
        }

        private void btnReadOnline_Click_1(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate("/View/Book/BookReadPage.xaml");
        }

        //private void listDirectory_BeginLoadData_1(object sender, G.Controls.PageEventArgs e)
        //{

        //}
    }
}